package com.hardydou.data.service.impl;

import com.hardydou.common.result.ResultAssert;
import com.hardydou.data.mapper.YdIconMapper;
import com.hardydou.data.model.YdIcon;
import com.hardydou.data.service.IYdIconServce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author ：hardy
 * @description：
 * @date ：Created in 2021/1/31
 * @Copyright ：Hardydou.com
 */
@Service
public class YdIconServiceImpl implements IYdIconServce {

    @Autowired
    YdIconMapper iconMapper;

    @Override
    public void add(YdIcon icon) {
        ResultAssert.notNull(icon);
        iconMapper.insert(icon);
        if (icon.getTags().size() > 0) {
            iconMapper.setTags(icon);
        }
    }

    @Override
    public void update(YdIcon icon) {
        iconMapper.updateByPrimaryKeyWithBLOBs(icon);
    }

    @Override
    public YdIcon findById(Long iconId) {
        return iconMapper.selectByPrimaryKey(iconId);
    }

    @Override
    public void delete(Long iconId) {
        iconMapper.deleteByPrimaryKey(iconId);
        iconMapper.cleanTagsByIcon(new long[]{iconId});
    }

    @Override
    public List<YdIcon> list(Map params) {
        return iconMapper.list(params);
    }

    @Override
    public void deleteByIconId(long[] iconIds) {
        iconMapper.batchDel(iconIds);
        iconMapper.cleanTagsByIcon(iconIds);
    }
}
